package www.lagou.app;

import www.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import www.lagou.entity.Phone;

import java.sql.SQLException;
import java.util.List;

public class Test_02 {
    public static void main(String[] args) throws SQLException {
        /**
             需求1:  查询价格高于2000元，生产日期是2019年之前的所有手机
         *
         */

        Phone p = new Phone();
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        String sql ="SELECT * FROM phone WHERE DATE_FORMAT(prodate,'%Y-%m-%d')>'2019-01-01' AND  price >2000;";

        List<Phone> list = qr.query(sql, new BeanListHandler<Phone>(Phone.class));

        for (Phone phone:list) {
            System.out.println("价格大于两千，日期在2019年之前的手机有："+list);
        }
            //需求2:  查询所有颜色是白色的手机信息

        String sql1 = "SELECT * FROM phone WHERE color LIKE '%白色%'; ";
        List<Phone> list1 = qr.query(sql1, new BeanListHandler<Phone>(Phone.class));

            System.out.println("所有包含白色字样的手机有："+list1);


    }
}
